package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IPpywork;
import com.example.mymatch.model.Ppywork;
import com.example.mymatch.service.IPpyworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：谢楷诗
 */
@Service
public class IPpyworkServiceImpl implements IPpyworkService {
    @Autowired
    private IPpywork ppyworkMapper;
    @Override//添加方法
    public int insertPpywork(Ppywork ppywork){
        int ppyworkValue=0;
        //查看当前物业人员工作安排名称不能重复
        Ppywork ppywork1=new Ppywork();
        ppywork1.setWorkId(ppywork.getWorkId());
        List<Ppywork> getC =ppyworkMapper.getAllPpywork(ppywork1);
        if (getC.size()>=1){
            //不可以添加物业人员工作安排名称
            ppyworkValue=-1;
        }else {
            ppyworkValue=ppyworkMapper.insertPpywork(ppywork);
        }
        return ppyworkValue;
    }
    @Override
    public List<Ppywork> getAllPpywork(Ppywork ppywork){return ppyworkMapper.getAllPpywork(ppywork);}
    @Override
    public int updatePpywork(Ppywork ppywork){
        int ppyworkValue=0;
        //判断主键不能为0
        if (ppywork.getWorkId()!=0){
            //主键信息必须存在

            //名称不能重复

            ppyworkValue=ppyworkMapper.updatePpywork(ppywork);
        }
        return ppyworkValue;
    }
    @Override
    public int deletePpywork(Ppywork ppywork){
        int ppyworkValue=0;
        //判断主键不能为0
        if (ppywork.getWorkId()!=0){
            //主键是否与其他表有关联，如果关联，则先删除其它表的信息，或者给出此条信息不允许被删

            ppyworkValue=ppyworkMapper.deletePpywork(ppywork);
        }
        return ppyworkValue;
    }

    //单条查询
    @Override
    public Ppywork getPpywork(Ppywork ppywork){
        Ppywork ppywork1=new Ppywork();
        if (ppywork.getWorkId()!=0){
            ppywork1=ppyworkMapper.getPpywork(ppywork);
        }
        return ppywork1;
    }
}
